package com.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: 陈忠杰
 * @Date: 2021/07/02/15:29
 * @Description:
 */
public class LoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println("进入拦截器了,拦截的url是" + request.getRequestURL());
        HttpSession session = request.getSession();
        String isLogin = (String)session.getAttribute("isLogin");
        if ("1".equals(isLogin)){
            return true;
        }else{
            response.sendRedirect(request.getContextPath() + "/backlogin");
            return false;
        }
//        return true;
    }
}
